﻿using Acme.ConcreteMixDesign.EntityFrameworkCore;
using Acme.ConcreteMixDesign.Topics;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Primitives;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;

namespace Acme.ConcreteMixDesign.Repositories
{
    /// <summary>
    /// 实现自定义仓储，EfCoreRepository是Efcore中仓储接口的默认实现类
    /// </summary>
    public class TopicRepository : EfCoreRepository<ConcreteMixDesignDbContext, Topic, Guid>, ITopicRepository
    {
        public TopicRepository(IDbContextProvider<ConcreteMixDesignDbContext> dbContextProvider) : base(dbContextProvider)
        {
        }
        public async Task<Answer> FindAnswerByIdAsync(Guid topicId,bool include,CancellationToken cancellation)
        {
            var Answers = (await GetDbContextAsync()).Answers;
            var result = await Answers.FirstOrDefaultAsync(
                answer => answer.TopicId == topicId,
                GetCancellationToken(cancellation)
                );
            return result;
        }
    }
}
